<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        ul {
            list-style: none
        }

        .green {
            background: #4CAF50
        }
    </style>
</head>

<body>
    <ul class="wrap">
        <li class="demo demo1">1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
        <li>6</li>
        <li>7</li>
    </ul>
    <script>

        lis = document.querySelectorAll('.wrap li')
        let fn = function () {
            //    所有的li移除样式
            lis.forEach(element => element.classList.remove('green'))
            // 当前事件源对象加上此样式
            this.classList.add('green')
        }
        lis.forEach(element => {
            //  每个li绑定onmouseve事件
            element.onmouseover = fn
        })
    </script>

</body>

</html>